package cn.t.repository.impl;

import cn.t.converter.api.UnitConverter;
import cn.t.model.common.UnitDO;
import cn.t.persistence.entity.UnitPO;
import cn.t.persistence.mapper.UnitMapper;
import cn.t.repository.feign.UnitRepository;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * 单位(Unit)数据仓库
 *
 * @author s
 * @since 2024-06-12 13:33:18
 */
@Slf4j
@Repository
@AllArgsConstructor
public class UnitRepositoryImpl extends ServiceImpl<UnitMapper, UnitPO> implements UnitRepository {

    private final UnitConverter converter;

    @Override
    public List<UnitDO> getUnit(String type) {
        LambdaQueryWrapper<UnitPO> queryWrapper = new LambdaQueryWrapper<UnitPO>()
                .eq(StringUtils.hasText(type), UnitPO::getType, type);
        return converter.po2Model(this.list(queryWrapper));
    }
}
